package com.addcn.common.utils
{
	import flash.events.EventDispatcher;
	import it.gotoandplay.smartfoxserver.SmartFoxClient;
	import com.addcn.demo.data.ServerInfo;
	import com.addcn.demo.data.Global;
	/**
	 * sfs客服端
	 * @author lmzd
	 */
	public class FOGClient extends EventDispatcher
	{
		/**
		 * sfs客戶端實例
		 */
		public var client:SmartFoxClient;
		/**
		 * 本類對象
		 */
		private static var _instance:FOGClient;
		
		public function FOGClient() {
			if ( _instance != null ) {
				throw new Error("FOGClient為單例類,請使用getInstance()獲取實例!");
				return;
			}			
		}
		/**
		 * 初始化，創建連接
		 * @return	客戶端對象
		 */
		public function init(r_ip: String = null, r_port : uint = 0):SmartFoxClient {		
			client = new SmartFoxClient(true);
			var _ip = r_ip;
			var _port = r_port;
			if (_ip == null) {
				_ip = ServerInfo.getInstance().serverIp
			}
			if (_port == 0) {
				_port = ServerInfo.getInstance().serverPort
			}
			client.connect(_ip, _port);				
			return client;
		}
		/**
		 * 獲取實例化本類
		 * @return
		 */
		public static function getInstance():FOGClient {			
			if ( _instance == null ) {
				_instance = new FOGClient;
			}
			return _instance;
		}		
	}

}
